<?php

/**
 * XHTML_Title, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Title class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_I18n_Element.php";

/**
 * The XHTML_Title class is a handler for the title xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_Title extends XHTML_I18n_Element {
    
    // xhtml attributes
    
    /**
     * Unique identifier for the xhtml-title-tag.
     *
     * @var string
     */
    protected $id;
    
    
    // inner elements
    
    /**
     * Text for the title.
     *
     * @var string
     */
    protected $text;
    
    
    //Methods
    
    function __construct($text)
    {
        $this->text = $text;
    }
    
    /**
     * Sets the unique identifier.
     *
     * @param string $id
     */
    function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * Gets the unique identifier.
     *
     * @return string
     */
    function getId()
    {
        return $this->id;
    }
    
    /**
     * Sets the text for the title.
     *
     * @param string $text
     */
    function setText($text)
    {
        $this->text = $text;
    }
    
    /**
     * Gets the text that has been set for the title.
     *
     * @return string
     */
    function getText()
    {
        return $this->text;
    }
    

    // Overriding the toString method for a proper implementation.
    
    /**
     * Returns the string representation for echoing the class atributes.
     *
     * @return string
     */
    function toString()
    {
        $auxString = "<title".parent::toString();
        
        /*
         * Additions of the title own attributes to the return string.
         */
        if (isset($this->id)) {
            $auxString = $auxString."id=\"".$this->id."\" ";
        }
        
        $auxString = $auxString.">";
        
        /*
         * Additions of the inner elements of the title element to the return 
         * string.
         */
        $auxString = $auxString.$this->text;
        
        $auxString = $auxString."</title>\n";
        
        return $auxString;
    }
    
}

?>